﻿_Scripts = function()
{
   this.Scripts = new Array();
}

_Scripts.prototype =
{
   AddScript : function(key, script)
   {
      for(var i=0;i<this.Scripts.length;i++)
      {
         if (this.Scripts[i].key == key.toLowerCase())
         {
            WriteHistory("AddScript:Push:" + this.Scripts[i].JS.length);
            this.Scripts[i].JS.push(script);
            return;
         }         
      }
      
      WriteHistory("AddScript:Add:" + this.Scripts.length);
      //cannot find
      var obj = {}
      obj.key = key.toLowerCase();
      obj.JS = new Array();
      obj.JS.push(script);
      this.Scripts.push(obj);
   },
   
   FindKey : function(key)
   {
      for(var i=0;i<this.Scripts.length;i++)
      {
         if (this.Scripts[i].key == key.toLowerCase())
         {
            return this.Scripts[i];
         }
      }
      
      return null;
   },
   
   RunAllScripts : function()
   {
      WriteHistory("RunAllScripts: " + this.Scripts.length);
      for(var i=0;i<this.Scripts.length;i++)
      {
         var theScripts = this.Scripts[i];
         while(theScripts.JS.length > 0)
         {
            var JS = theScripts.JS.shift();
            WriteHistory(JS);
            //installScript(JS);
         }
      }
   }
}

var JSScripts = new _Scripts();